package _100SameTree;

public class CSolution {

  public static void main(String[] args) {
    System.out.println("aa");
    TreeNode pl = new TreeNode(2);
      TreeNode pr = new TreeNode(3);
      TreeNode ql = new TreeNode(2);
      TreeNode qr = new TreeNode(4);
      TreeNode p = new TreeNode(1,pl,pr);
      TreeNode q = new TreeNode(1,ql,qr);
    System.out.println(isSameTree(p, q));
//    System.out.println(isSameTree(p, q));
  }

  private static boolean isSameTree(TreeNode p, TreeNode q) {
      if(p==null && q == null) {
          return true;
      }
    if ((p==null && q!=null)||(p!=null && q == null) || p.val != q.val) {
      return false;
    }
    if(p==null && q == null) {
        return true;
    }
    return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
  }
}
